package edu.groupservice.feignFailBack;

import edu.groupservice.entity.User;
import edu.groupservice.feign.UserServiceFeign;
import edu.groupservice.feign.UserServiceFeignWithFallBackFactory;
import feign.Contract;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.hystrix.FallbackFactory;
import feign.hystrix.HystrixFeign;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by JPhoebe on 2017-7-9.
 */
@Component
public class UserServiceFeignFallbackFactory implements FallbackFactory<UserServiceFeign> {

    @Override
    public UserServiceFeign create(Throwable throwable) {

        // 打印异常
        LoggerFactory.getLogger(this.getClass()).info(throwable.getMessage());

        //需要一个factory接口  继承 feign 的接口
        return new UserServiceFeignWithFallBackFactory(){
            @Override
            public User findUserById(long id) {
                User user = new User();
                user.setAge(9);
                user.setId(0);
                user.setName("error/Factory");
                user.setRequestPort(0000);
                return user;
            }
        };
    }

}
